import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

public class Solution {
    public static void main1(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(2);
        list.add(1);
        list.add(3);
        list.forEach(x-> System.out.print(x));
        System.out.println();
        System.out.println("==================");
        list.sort(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1.compareTo(o2);
            }
        });

        list.sort((o1,o2) -> o1-o2);
        list.forEach(x-> System.out.print(x));
    }

    public static void main2(String[] args) {
        HashMap<String,Integer> map = new HashMap<>();
        map.put("a",1);
        map.put("b",2);
        map.put("c",3);
        map.forEach(new BiConsumer<String, Integer>() {
            @Override
            public void accept(String s, Integer integer) {
                System.out.println("key:" + s + " " + "value:"+integer);
            }
        });

        //使用 lambda 表达式简化后的结果
        map.forEach((key,val) -> System.out.println("key:" + key + " " + "value:"+val));

        //map.forEach();
    }

    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("sugar");
        list.add("hello");
        list.add("Lambda");
        list.forEach(s-> System.out.print(s + " "));
        System.out.println();
        list.sort((s1,s2)-> s1.compareTo(s2));
        list.forEach(s-> System.out.print(s + " "));
    }
}
